package com.example.controller;

import com.example.pojo.OrderDetails;

import com.example.service.impl.OrderDetailsServiceImpl;
import com.example.tools.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class OrderDetailsController {

    @Autowired
    private OrderDetailsServiceImpl orderDetailsService;

    /**
     * 获取订单明细信息
     * @return
     */
    @GetMapping("/getOrderDetail")
    public Result getOrderDetails(@RequestParam("id") Integer id){
        //log.info(Integer.toString(id));
        List<OrderDetails> orderDetails=orderDetailsService.getDetails(id);
        return Result.success(orderDetails);
    }

    /**
     * 修改订单明细信息
     */
    @PostMapping("/changeOrderDetails")
    public Result changeOrderDetails(@RequestBody OrderDetails orderDetails){
        orderDetailsService.changeOrderDetails(orderDetails);
        return Result.success();
    }

    /**
     * 删除订单明细
     * @param id
     * @return
     */
    @DeleteMapping("/deleteOrderDetails")
    public Result deleteOrderDetails(String id){
        orderDetailsService.deleteOrderDetails(id);
        return Result.success();
    }

    /**
     * 添加订单明细
     * @param orderDetails
     * @return
     */

    @PostMapping("/addOrderDetails")
    public Result addOrderDetails(@RequestBody List<OrderDetails> orderDetails){
        orderDetailsService.addOrderDetails(orderDetails);
        return Result.success();
    }
    
}
